﻿/*
 * @author: wizardc
 */

using Dou.UI;
using UnityEditor;
using SuperScrollViewEditor;
using UnityEngine;
using UnityEngine.UI;

namespace DouEditor.UI
{
    [CustomEditor(typeof(SuperLoopList), true)]
    public class SuperLoopListEditor : LoopListViewEditor2
    {
        [MenuItem("GameObject/DouUI/SuperLoopList", false, 10)]
        private static void CreateUI(MenuCommand menuCommand)
        {
            var go = UIEditorUtil.CreateUIElement("SuperLoopList");

            var image = go.AddComponent<DImage>();
            image.SetColor(1, 1, 1, 0);
            
            var scrollRect = go.AddComponent<ScrollRect>();
            
            go.AddComponent<SuperLoopList>();
            
            var childViewport = UIEditorUtil.CreateGameObject("Viewport", go.transform);
            var viewport = childViewport.GetComponent<RectTransform>();
            viewport.anchorMin = Vector2.zero;
            viewport.anchorMax = Vector2.one;
            viewport.pivot = new Vector2(0, 1);
            viewport.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
            viewport.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);
            scrollRect.viewport = viewport;
            childViewport.AddComponent<RectMask2D>();
            
            var childContent = UIEditorUtil.CreateGameObject("Content", childViewport.transform);
            var content = childContent.GetComponent<RectTransform>();
            content.anchorMin = new Vector2(0, 1);
            content.anchorMax = Vector2.one;
            content.pivot = new Vector2(0, 1);
            content.anchoredPosition = Vector2.zero;
            content.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
            content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 300);
            scrollRect.content = content;

            UIEditorUtil.PlaceUIElementRoot(go, menuCommand);
        }
    }
}
